package com.gule.gl.leetcode.editor.javabook;

import com.gule.gl.leetcode.editor.cn.definition.TreeNode;

import java.util.Objects;

/**
 * @Auther: gl
 * @Date: 2020/2/12 12:50
 * @Description:
 */
@Deprecated
public class TreeToLinkedList {
    TreeNode pHead = null;
    TreeNode pEnd = null;

    /**
     * 将树转成一个双向连表，采用中序遍历
     *
     * @param root
     */
    void treeToLinkedList(TreeNode root) {
        if (Objects.isNull(root)) {
            return;
        }
        //左 todo 不是很理解
        treeToLinkedList(root.left);

        root.left = pEnd;

        if (Objects.isNull(pEnd)) {
            pHead = root;
        } else {
            pEnd.right = root;
        }
        pEnd = root;
        //右
        treeToLinkedList(root.right);
    }

}
